<?

class kemlDriver {

	/* ---------------------------------
	 |            PUBLIQUE            |
	 ---------------------------------*/



	function initData () {
		//Aucune data a initialiser pour dossiers et fichiers.
	}


	function Purge() {
		//Aucun champ a purger, car on ne peut pas en creer
	}

	function resetSearch(){
		$this->Beacons = Array();
		$this->FormInt = 0;
		$this->BlocInt = 0;
		$this->ColInt = 0;
		$this->LineInt = 0;
	}

	function Search($Recherche="",$BlurSearch=false){
		if(!$this->enCours[count($this->enCours)-1][0]['Data']){
			$Emplacement = $this->enCours[count($this->enCours)-1][0]['Path'];
			if (!file_exists($Emplacement)) return false;
			if (!$this->Memory = file_get_contents($Emplacement)) return false;
		}else {
			$this->Memory=$this->enCours[count($this->enCours)-1][0]['Data'];
		}
		kemlDriver::createBeaconTab();
		Process::processRecursiv($this->Memory,$this->BaliseTemp);
		for ($i=0;$i<count($this->Beacons);$i++){
			if($this->Beacons[$i]['Id'] == $Recherche){
				$Results[0] = $this->Beacons[$i];
			}
		}
		kemlDriver::resetSearch();
		return $Results;
	}

	function searchAll(){
	}


	function multiSearch($Recherche){
	}


	function getReference(){
	}


	function getReflexiveRelatives($id,$typeSearch,$Parametres=''){
		$this->Memory=$this->enCours[count($this->enCours)-1][0]['Data'];
		kemlDriver::createBeaconTab();
		Process::processRecursiv($this->Memory,$this->BaliseTemp);
		$Resultats = $this->Beacons;
		kemlDriver::resetSearch();
		return $Resultats;
	}


	function getBeacon($Var,$Data,$SupVar){
		$Var = urldecode ($Var);
		$Data = urldecode ($Data);
		$SupVar = urldecode ($SupVar);
		$int=count($this->Beacons);
		$this->Beacons[$int]['Type'] = $SupVar;
		$this->Beacons[$int]['Data'] = $Data;
		for ($i=0;$i<count($this->BaliseTemp);$i++){
			if ($this->BaliseTemp[$i]['BEACON'] == $SupVar){
				$this->Beacons[$int]['Id'] = $SupVar.'_'.($this->BaliseTemp[$i]['COUNT']+1);
				$this->BaliseTemp[$i]['COUNT']++;
			}
		}
		$Tab = explode("|",$Var);
		for ($i=0;$i<count($Tab);$i++){
			$j=$i+1;
			eval("\$this->Beacons[$int][Param".$j."]= \"".$Tab[$i]."\";");
		}
	}

	function getFkeyRelatives($id,$typeSearch,$Recherche,$Card,$Parametres=''){
		if(!$this->enCours[count($this->enCours)-1][0]['Data']){
			$Emplacement = $this->enCours[count($this->enCours)-1][0]['Path'];
			if (!file_exists($Emplacement)) return false;
			if (!$this->Memory = file_get_contents($Emplacement)) return false;
		}else {
			$this->Memory=$this->enCours[count($this->enCours)-1][0]['Data'];
		}
		kemlDriver::createBeaconTab();
		Process::processRecursiv($this->Memory,$this->BaliseTemp);
		$Resultats = $this->Beacons;
		kemlDriver::resetSearch();
		return $Resultats;
	}

	function createBeaconTab(){
		$this->BaliseTemp = Array (
		Array("BEACON"=>"FORM","FUNCTION"=>"getBeacon","VAR"=>"FORM","COUNT"=>0),
		Array("BEACON"=>"BLOC","FUNCTION"=>"getBeacon","VAR"=>"BLOC","COUNT"=>0),
		Array("BEACON"=>"COL","FUNCTION"=>"getBeacon","VAR"=>"COL","COUNT"=>0),
		Array("BEACON"=>"LINE","FUNCTION"=>"getBeacon","VAR"=>"LINE","COUNT"=>0)
		);
	}

	function insertObject(){
		$Tab = $GLOBALS['Systeme']->Modules[$this->Module]->callData($this->NewProperties['URL']);
		if (!sizeof($Tab)) return false;
		$NewBeacon = '['.$this->NewProperties['Type']." ";
		for ($i=1;$i<6;$i++){
			if (array_key_exists("Param".$i,$this->NewProperties)){
				if ($Flag) $NewBeacon.="|";
				$NewBeacon.= $this->NewProperties["Param".$i];
				$Flag=true;
			}
		}
		$NewBeacon.="]\r\n".$this->NewProperties['Data']."\r\n[/".$this->NewProperties['Type']."]";
	}


	function createData(){
	}

	function insertKey($Tab,$Type){
	}


	function Erase($Id){
	}


	function EraseAssociation($Relative,$ObjId,$Type){
	}


	/*---------------------------------
	 |           PRIVEE               |
	 ---------------------------------*/

	/*---------------------------------
	 |           CREATION              |
	 ---------------------------------*/

	function init() {
	}


	function saveData(){
	}


	/*---------------------------------
	 |           RECHERCHE             |
	 ---------------------------------*/


	/* Cette fonction range et classe dans un tableau les donnees trouvees.
	 Renvoi: le tableau de resultat.
	 Parametres: les donnees trouvees dans la base de donnees, la recherche effectuee*/
	function analyzeSearch($Donnees, $Recherche) {
		$Resultat= Array();
		$compteur=0;
		$totalCibles=count($this->Cibles);
		//On procede au calcul de la note que l'on enregistre, avec le reste, dans le tableau final
		while($Enregistrement=mysql_fetch_assoc($Donnees)){
			foreach ($this->Cibles as $valeurCible){
				foreach ($Enregistrement as $clefEnr=>$valeurEnr){
					$Resultat[$compteur][$clefEnr] = $valeurEnr;
					//Calcul de la note
					$note= (preg_match('!'.$Recherche.'!i', $valeurEnr) && $clefEnr== $valeurCible['nom']) ? $this->calcNote($valeurEnr,$Recherche,$valeurCible['searchorder']): 10;
				}
			}
			$Resultat[$compteur]['note'] = $note;
			$compteur++;
		}
		$Resultat = $this->bubbleSort($Resultat,'note');
		$Resultat=$this->setSearchOrder($Resultat);
		return $Resultat;
	}

	/*---------------------------------
	 |          TEST/AUTO              |
	 ---------------------------------*/

	function getTableName(){
	}

	function findReflexive(){
	}

	function getTime(){
	}
}